#include "qpointfseditor.h"

#include "qpointfseditordialog.h"

#include "../../shared/property/qabstractproperty.h"
#include "../../shared/host/qabstracthost.h"
#include "../undocommand/qpropertychangedundocommand.h"
#include "../../shared/qpropertyfactory.h"

#include <QFontDialog>

QPointFsEditor::QPointFsEditor(QAbstractProperty *property,QUndoStack* stack, QWidget *parent):
    QButtonCommonEditor(property,stack,parent),
    m_undo_stack(stack)
{
}

void QPointFsEditor::btn_clicked()
{
    QPointFsEditorDialog dlg(m_property->get_value(),m_property->get_property("name")=="line_points"?PT_LINE:PT_POLYGON,this);

    dlg.exec();

    if(dlg.get_ret()==1)
    {
        QVariant v=dlg.get_value();
        if(!m_property->cmp(v))
        {
            QPropertyChangedUndoCommand *cmd=new QPropertyChangedUndoCommand(
                        m_property->get_host()->get_uuid(),
                        m_property->get_name(),
                        m_property->get_value(),v);
            m_undo_stack->push(cmd);
        }
    }
}

qRegisterPropertyEditor(PointFs,QPointFsEditor)
